<?Php
	require_once('../Model/getconfig.php');
	//require_once('includes/checksession.php');
	$randomnumer= rand(5, 100000);
	
	function getExtension($str) {
		$i = strrpos($str,".");
		if (!$i) { return ""; }
			$l = strlen($str) - $i;
			$ext = substr($str,$i+1,$l);
			return $ext;
	}		

?>
<?php
//If the form is submitted

			//$username="F".$randomnumer;//trim($_REQUEST['textUsername']);
			//$password=$randomnumer;//trim($_REQUEST['textpassword']);	
			//$confirmpassword=trim($_REQUEST['textconfirmpassword']);		

//contact  details reading			
			//$RegStatus=$_REQUEST['cmbRegStatus'];
			$userid=trim($_REQUEST['userid']);
			$username=trim($_REQUEST['username']);
			$Name=trim($_REQUEST['texName']);
			$Typeofbusiness=trim($_REQUEST['cmbTypeofbusiness']);	
			$Businesssublist=trim($_REQUEST['cmbBusinesssublist']);	
			$Titile=trim($_REQUEST['texTitile']);
			$Address1=trim($_REQUEST['texaddr']);
			$contState=trim($_REQUEST['cmbcontState']);	
			$District=trim($_REQUEST['cmbDist']);
			$Email=trim($_REQUEST['textEmail']);	
			$website=trim($_REQUEST['textwebsite']);						
			$Phone=trim($_REQUEST['phone']);
			$Details=trim($_REQUEST['texdetails']);
			//$coupon=trim($_REQUEST['textregpin']);
			
			$image1=$_FILES['image1']['name'];
			$image2=$_FILES['image2']['name'];
			$image3=$_FILES['image3']['name'];
			$image4=$_FILES['image4']['name'];
			
		
	/*		if($username === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid Username!";
			}
			else
			{
				$pnid=0;
				$arrMenu=Model_membermaster::checkUserexist($username);
				foreach($arrMenu as $objMenu){ 
					$pnid=$objMenu->getuserid();
					if($pnid>0)
					{							
						$hasError = true;				
						$errorMessage = "You are entered username already exist( Enter new username)!";
					}
				}
							
			}
		
			if($password === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid Password!";
			}
*/
			
		//	if($confirmpassword === '') {
		//		$hasError = true;
		//		$errorMessage = "Please enter a valid Password!";
		//	}
		//	if($password !== $confirmpassword ) {
		//		$hasError = true;
		//		$errorMessage = "Please enter a valid Password ( New password and confirm password are not matching!";
		//	}	
			
			if($Name === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid Name!";
			}
	
			if($Typeofbusiness === '') {
				$hasError = true;
				$errorMessage = "Please select type of business!";
			}
						
			if($Address1 === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid Address!";
			}

			
		/*	if($pincode === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid Pincode!";
			}
			else if (!preg_match("/^[0-9]/", trim($_POST['texpincode']))) {
				$hasError = true;
				$errorMessage = "Please enter a valid Pincode (Digits only)!";
			}				
*/
			
			if($contState === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid state!";
			}
			
			if($District === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid District!";
			}			

	/*		
			if($city === '') {
				$hasError = true;
				$errorMessage = "Please enter a valid city!";
			}
*/
			
/*			if(trim($_POST['textEmail']) === '')  {
			//	$hasError = true;
			} else if (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", trim($_POST['textEmail']))) {
				$hasError = true;
				$errorMessage = "Please enter a valid email address!";
			}	
			
//coupon checking

		$couponletter = substr($coupon, 0, -1);
		if($couponletter=="R")
		{

			$arrUsers=Model_prepaid::checkCoupon($coupon);  
			if(count($arrUsers)>0){
				$objMemmaster=$arrUsers[0];		
				$Couponstatus=$objMemmaster->getCouponstatus();
				
				if($Couponstatus=="Y")
				{			
					$hasError = true;				
					$errorMessage = "Invalid Registration Pin( This Registration Pin is already used)!";
				}						
			}
			else{			
					$hasError = true;				
					$errorMessage = "Invalid Registration Pin( This Registration Pin is not existing)!";
				}
				
		}else{			
					$hasError = true;				
					$errorMessage = "Invalid Registration Pin( This Pin is not allowed for Registration, This pin for Activation)!";
				}												
			
*/	

//PHOTO 1 UPLOADING
if ($image1!="") 
{		  

	 //$randam= rand(5, 100000);		

	//define a maxim size for the uploaded images in Kb
 	 define ("MAX_SIZE","1000"); 

     $errors=0;
 	 $image1=$_FILES['image1']['name'];
 	 if ($image1!="") 
 	 {
 	 $filename = stripslashes($_FILES['image1']['name']);
  	 $extension = getExtension($filename);
 	 $extension = strtolower($extension);
 	 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
 	 {
 		echo "<div align='center'><span class='style41'>Image  extension type is not allowed for image 1</span></div><br>";
		echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
 		$errors=1;
 	 }
 	 else
 	 {
		 $size=filesize($_FILES['image1']['tmp_name']);
		 if ($size > MAX_SIZE*1024)
		 {
			echo "<div align='center'><span class='style41'>Image 1 have exceeded the size limit!</span></div><br>";
			echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
			$errors=1;
		 }
	 }
	 }
	 else {
	 echo "<div align='center'><span class='style41'>Please select an image for uploading</span></div><br>";
	 echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
	 }
}
else
{
	$errors=1;
}																							


//PHOTO 2 UPLOADING
if ($image2!="") 
{		  

	 //$randam= rand(5, 100000);		

	//define a maxim size for the uploaded images in Kb
 	 define ("MAX_SIZE","1000"); 

     $errors2=0;
 	 $image2=$_FILES['image2']['name'];
 	 if ($image2!="") 
 	 {
 	 $filename = stripslashes($_FILES['image2']['name']);
  	 $extension = getExtension($filename);
 	 $extension = strtolower($extension);
 	 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
 	 {
 		echo "<div align='center'><span class='style41'>Image  extension type is not allowed for image 1</span></div><br>";
		echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
 		$errors2=1;
 	 }
 	 else
 	 {
		 $size=filesize($_FILES['image2']['tmp_name']);
		 if ($size > MAX_SIZE*1024)
		 {
			echo "<div align='center'><span class='style41'>Image 2 have exceeded the size limit!</span></div><br>";
			echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
			$errors2=1;
		 }
	 }
	 }
	 else {
	 echo "<div align='center'><span class='style41'>Please select an image for uploading image 2</span></div><br>";
	 echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
	 }
}
else
{
	$errors2=1;
}


//PHOTO 3 UPLOADING
if ($image3!="") 
{		  

	 //$randam= rand(5, 100000);		

	//define a maxim size for the uploaded images in Kb
 	 define ("MAX_SIZE","1000"); 

     $errors3=0;
 	 $image3=$_FILES['image3']['name'];
 	 if ($image3!="") 
 	 {
 	 $filename = stripslashes($_FILES['image3']['name']);
  	 $extension = getExtension($filename);
 	 $extension = strtolower($extension);
 	 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
 	 {
 		echo "<div align='center'><span class='style41'>Image  extension type is not allowed for image 1</span></div><br>";
		echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
 		$errors3=1;
 	 }
 	 else
 	 {
		 $size=filesize($_FILES['image3']['tmp_name']);
		 if ($size > MAX_SIZE*1024)
		 {
			echo "<div align='center'><span class='style41'>Image 3 have exceeded the size limit!</span></div><br>";
			echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
			$errors3=1;
		 }
	 }
	 }
	 else {
	 echo "<div align='center'><span class='style41'>Please select an image for uploading image 3</span></div><br>";
	 echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
	 }
}
else
{
	$errors3=1;
}



//PHOTO 4 UPLOADING
if ($image4!="") 
{		  

	// $randam=rand(5, 100000);		

	//define a maxim size for the uploaded images in Kb
 	 define ("MAX_SIZE","1000"); 

     $errors4=0;
 	 $image4=$_FILES['image4']['name'];
 	 if ($image4!="") 
 	 {
 	 $filename = stripslashes($_FILES['image4']['name']);
  	 $extension = getExtension($filename);
 	 $extension = strtolower($extension);
 	 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
 	 {
 		echo "<div align='center'><span class='style41'>Image  extension type is not allowed for image 1</span></div><br>";
		echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
 		$errors4=1;
 	 }
 	 else
 	 {
		 $size=filesize($_FILES['image4']['tmp_name']);
		 if ($size > MAX_SIZE*1024)
		 {
			echo "<div align='center'><span class='style41'>Image 3 have exceeded the size limit!</span></div><br>";
			echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
			$errors4=1;
		 }
	 }
	 }
	 else {
	 echo "<div align='center'><span class='style41'>Please select an image for uploading image 3</span></div><br>";
	 echo "<div align='center'> <a href='javascript:history.back();'>Back</a></div>";
	 }
}
else
{
	$errors4=1;
}

																						
		//If there is no error, send the email
		if(!isset($hasError)) {	
		
/*		$arrMenu=Model_maxtab::get_Maxtabvalue('REGISTRATION');
			foreach($arrMenu as $objMenu){ 
				$maxtabvalue=$objMenu->getValue(); 
				$maxtabvalue=$maxtabvalue+1;	
			}	
*/			
//echo	$custsql="insert into membermaster (pn_id,c_username,c_password,c_first_name,c_typ_Business,c_business_subfield,c_titile,c_district,c_state,c_address,c_email,c_mobil,c_details,ref_id,c_status) values ('$maxtabvalue','$username','$password','$Name','$Typeofbusiness','$Businesssublist','$Titile','$District','$contState','$Address1','$Email','$Phone','$Details','$exeusername','Y')";		

//	$custsql="insert into membermaster (pn_id,c_username,c_password,c_first_name,c_typ_Business,c_business_subfield,c_district,c_state,c_address,c_email,c_mobil,c_details,ref_id,c_status) values ('$maxtabvalue','$username','$password','$Name','$Typeofbusiness','$Businesssublist','$District','$contState','$Address1','$Email','$Phone','$Details','$exeusername','Y')";	
	
	$custsql="update membermaster set c_first_name='$Name',c_typ_Business='$Typeofbusiness',c_business_subfield='$Businesssublist',c_district='$District',c_state='$contState',c_address='$Address1',c_email='$Email',c_website='$website',c_mobil='$Phone',c_details='$Details' where c_username='$username' ";
			//echo $custsql;		
			$objDbManager=new Dbo_DbManager();
			$intMemmasterId=$objDbManager->dbexecute($custsql);		
			
		
			$arrMenu=Model_typeofbusiness::get_Memberscount($Typeofbusiness);
			foreach($arrMenu as $objMenu){ 
				$typeofbusinesscount=$objMenu->getMemberscount(); 
				$typeofbusinesscount=$typeofbusinesscount+1;	
			}				
			
			$arrMenu=Model_businesslist::get_Memberscount($Businesssublist);
			foreach($arrMenu as $objMenu){ 
				$businesslistcount=$objMenu->getMemberscount(); 
				$businesslistcount=$businesslistcount+1;	
			}	
			
			$typeofbusinesssql="update typeofbusiness set  N_MEMBERSCOUNT='$typeofbusinesscount' where C_TYPEOFBUSINESS='$Typeofbusiness' ";		
			//echo $typeofbusinesssql;		
			$objDbManager=new Dbo_DbManager();
			$intMemmasterId=$objDbManager->dbexecute($typeofbusinesssql);	
			
			$businesslistsql="update businesslist set  N_MEMBERSCOUNT='$businesslistcount' where C_BUSINESSINFO='$Businesssublist' ";		
			//echo $businesslistsql;		
			$objDbManager=new Dbo_DbManager();
			$intMemmasterId=$objDbManager->dbexecute($businesslistsql);		
			
			
			//photo uploading
				 if($errors!=1) 
				 {
						$randam= rand(5, 100000);	
						$imgname=$userid."-".$randam;
					
						// $image_name="$userid"."$username".".".$extension;
						 $image_name1="$imgname".".".$extension;
						 $newname="../WebUploads/uploadedimages/".$image_name1;
						 $copied = copy($_FILES['image1']['tmp_name'], $newname);

						$sqlpropimage="insert into  generalimage (nid,cimagename,c_type) values ('$userid','$image_name1','GENERAL') "; 
						$objDbManager=new Dbo_DbManager();
						$intMemmasterId=$objDbManager->dbexecute($sqlpropimage);			

				 }		
				 
			//photo uploading
				 if($errors2!=1) 
				 {
						$randam= rand(5, 100000);	
						$imgname=$userid."-".$randam;
					
						// $image_name="$userid"."$username".".".$extension;
						 $image_name2="$imgname".".".$extension;
						 $newname="../WebUploads/uploadedimages/".$image_name2;
						 $copied = copy($_FILES['image2']['tmp_name'], $newname);

						$sqlpropimage="insert into  generalimage (nid,cimagename,c_type) values ('$userid','$image_name2','GENERAL') "; 
						$objDbManager=new Dbo_DbManager();
						$intMemmasterId=$objDbManager->dbexecute($sqlpropimage);			

				 }		
			//photo uploading
				 if($errors3!=1) 
				 {
						$randam= rand(5, 100000);	
						$imgname=$userid."-".$randam;
					
						// $image_name="$userid"."$username".".".$extension;
						 $image_name3="$imgname".".".$extension;
						 $newname="../WebUploads/uploadedimages/".$image_name3;
						 $copied = copy($_FILES['image3']['tmp_name'], $newname);

						$sqlpropimage="insert into  generalimage (nid,cimagename,c_type) values ('$userid','$image_name3','GENERAL') "; 
						$objDbManager=new Dbo_DbManager();
						$intMemmasterId=$objDbManager->dbexecute($sqlpropimage);			

				 }	
			//photo uploading
				 if($errors4!=1) 
				 {
						$randam= rand(5, 100000);	
						$imgname=$userid."-".$randam;
					
						// $image_name="$userid"."$username".".".$extension;
						 $image_name4="$imgname".".".$extension;
						 $newname="../WebUploads/uploadedimages/".$image_name4;
						 $copied = copy($_FILES['image4']['tmp_name'], $newname);

						$sqlpropimage="insert into  generalimage (nid,cimagename,c_type) values ('$userid','$image_name4','GENERAL') "; 
						$objDbManager=new Dbo_DbManager();
						$intMemmasterId=$objDbManager->dbexecute($sqlpropimage);			

				 }					 			 																	
										 		 																	
							
			$success=true;
		}
			
?>		
<?php if(isset($success) == true) { ?>
	<div class="ok_box">
		<h3>Thanks, <?php echo $Name;?></h3>
		<p>Your Updation was successfully completed. Please login and upload your details.</p>
	</div>
<?php } ?>

<?php if(isset($hasError) ) { ?>
	<div class="error_box">
		There was an error submitting the form.
		<br />
		<?php echo $errorMessage;?>
	</div>
<?php } ?>